package com.heima.article.conreoller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.AuthorService;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/author")
public class AuthorController {


    @Autowired
    private AuthorService authorService;

    /**
     * 根据id 查询作者是否勋在
     * @param
     * @return
     */
    @GetMapping("/findByUserId/{id}")
    public ResponseResult findByUserId(@PathVariable("id") Integer userId){
        return ResponseResult.okResult(authorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId , userId)));
    }



    @PostMapping("/save")
    public ResponseResult saveAuthor(@RequestBody ApAuthor  apAuthor){
        authorService.save(apAuthor);
        return ResponseResult.okResult(apAuthor);

    }




}
